import PropTypes from "prop-types";
function myValidate(props, propName, componentName) {
	if (
		Number.isInteger(props[propName]) &&
		props[propName] >= 0 &&
		props[propName] <= 100
	) {
		return null;// 成功
	} else {
		return new Error(
			`${componentName}的属性${propName}必须是整数` + `,且>=0,<=100`
		);
	}
}
function Comment({ author, message, likes, topic }) {
	return (
		<div>
			<div className='author'>{author}</div>
			<div className='message'>{message}</div>
			<div className='likes'>
				点赞：{likes > 0 ? `${likes}人点赞` : `无人点赞`}
			</div>
			<div className='topic'>{topic}</div>
		</div>
	);
}
Comment.propTypes = {
	author: PropTypes.string.isRequired,
	message: PropTypes.string,
	likes: PropTypes.number,
	topic: PropTypes.oneOf(["时尚", "新闻", "电竞"]),
	hot: myValidate,
};

export default Comment;
